package com.wbs.shop.nuby.view.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.wbs.shop.nuby.R;
import com.wbs.shop.nuby.bean.GoodsBean;
import com.wbs.shop.nuby.utils.GlideUtils;
import com.wbs.shop.nuby.view.base.BaseRecyclerAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhoucl on 2017/12/21 0021.
 */

public class GoodsAdapter extends BaseRecyclerAdapter<GoodsAdapter.ViewHolder, GoodsBean> {

    public GoodsAdapter(Context mContext) {
        super(mContext);
    }

    @Override
    public int getItemLoayoutId() {
        return R.layout.item_goods;
    }

    @Override
    public ViewHolder onCreateViewHolder(View rootView, int viewType) {
        return new ViewHolder(rootView);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, GoodsBean goodsBean, int position) {
        holder.productName.setText(goodsBean.getName());
        holder.unitPrice.setText(mContext.getString(R.string.text_money, goodsBean.getPrice()));
        GlideUtils.load(mContext, goodsBean.getImgUrl(), holder.pimgurl);
        holder.itemView.setTag(position);
        holder.itemView.setOnClickListener(this::onClickAdapter);
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.pimgurl)
        ImageView pimgurl;
        @BindView(R.id.productName)
        TextView productName;
        @BindView(R.id.unitPrice)
        TextView unitPrice;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
